import Vue from 'vue'
import VueRouter from 'vue-router'
// import { store } from "vuex";
import store from '../store'

Vue.use(VueRouter);
/* Layout */
import Layout from '@/layout'
/* 路由 */
//import menuRouter from './modules/menus.js';
/* 客户经理路由 */
//import managerRouter from './modules/manager.js';
/* 管理员路由 */
//import adminRouter from './modules/admin.js';
/* 超级管理员 */
//import superRouter from './modules/super.js';
/* 政府部门 */
//import govRouter from './modules/gov.js';
/* 征信机构 */
//import creditRouter from './modules/credit.js';


/* 固定路由 */
export const constantRoutes = [{
    path: '/',
    component: Layout,
    hidden: true,
    children: [{
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
    }]
}, {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
},
{
    path: '/calogin',
    component: () => import('@/views/login/login'),
    hidden: true
},
{
    path: '/unifyLogin',
    component: () => import('@/views/login/unifyLogin'),
    hidden: true
},
{
    path: '/first_login',
    component: () => import('@/views/login/first-login'),
    hidden: true
},
{
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
},
{
    path: '/403',
    component: () => import('@/views/error-page/403'),
    hidden: true
},
]

/* 异步路由 */
// export const asyncRoutes = [
//     ...menuRouter,
//     {
//         path: '*',
//         redirect: '/404',
//         hidden: true
//     }
// ];

const createRouter = () => new VueRouter({
    mode: 'history', // require service support
    base: '/jrfk/i/',
    scrollBehavior: () => ({
        y: 0
    }),
    
    // routes: [...constantRoutes, ...asyncRoutes]
    routes: constantRoutes
})
// console.log([...constantRoutes, ...asyncRoutes], '异步路由')
// console.log(accessRoutes, '获取动态路由')
// console.log(store.getters.roles, 'index.js')
// console.log(store.getters.roleId, 'index.js')
const router = createRouter();
/* 重置路由 */
export function resetRouter() {
    store.commit('permission/SET_ONERUN','true');
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
